package com.cellulam.framework.core.tools;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.RandomUtils;

import java.util.List;

@Slf4j
public class UniqueRandomSelector<T> {

    private final List<T> data;

    public UniqueRandomSelector(List<T> data) {
        this.data = data;
    }

    public T next() {
        if (CollectionUtils.isEmpty(data)) {
            log.warn("没有数据了");
            return null;
        }
        T result = this.data.get(RandomUtils.nextInt(0, data.size()));
        this.data.remove(result);
        return result;
    }
}
